package org.jeecg.modules.assets.service.impl;

import com.alibaba.fastjson.util.TypeUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.assets.entity.AssetsManger;
import org.jeecg.modules.assets.entity.DeptExt;
import org.jeecg.modules.assets.mapper.DeptExtMapper;
import org.jeecg.modules.assets.service.IAssetsMangerService;
import org.jeecg.modules.assets.service.IDeptExtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 部门扩展表
 * @Author: jeecg-boot
 * @Date: 2023-12-15
 * @Version: V1.0
 */
@Service
public class DeptExtServiceImpl extends ServiceImpl<DeptExtMapper, DeptExt> implements IDeptExtService {


    @Autowired
    private IAssetsMangerService assetsMangerService;

    @Override
    public void updateDeptExt(DeptExt deptExt) {

        QueryWrapper qw = new QueryWrapper();
        qw.eq("dept_id", deptExt.getDeptId());
        AssetsManger one = assetsMangerService.getOne(qw);
        if (one != null) {
            one.setDeptName(deptExt.getDeptName());
            one.setUserId(TypeUtils.castToInt(deptExt.getAssetsUserId()));
            one.setUserName(deptExt.getAssetsUserName());
            one.setDeptId(TypeUtils.castToInt(deptExt.getDeptId()));
            one.setCreateTime(deptExt.getCreateTime());
            assetsMangerService.updateById(one);
        } else {
            AssetsManger assetsManger = new AssetsManger();
            assetsManger.setDeptName(deptExt.getDeptName());
            assetsManger.setUserId(TypeUtils.castToInt(deptExt.getAssetsUserId()));
            assetsManger.setUserName(deptExt.getAssetsUserName());
            assetsManger.setDeptId(TypeUtils.castToInt(deptExt.getDeptId()));
            assetsManger.setCreateTime(deptExt.getCreateTime());
            assetsMangerService.save(assetsManger);
        }
        updateById(deptExt);

    }
}
